package com.kaiwukj.android.ufamily.mvp.ui.page.service.property.notice;

import androidx.annotation.NonNull;

import com.kaiwukj.android.mcas.mvp.BasePresenter;
import com.kaiwukj.android.mcas.utils.RxLifecycleUtils;
import com.kaiwukj.android.ufamily.mvp.http.callback.ApiCallBack;
import com.kaiwukj.android.ufamily.mvp.http.entity.base.ListResp;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.CommunityNoticeResult;
import com.kaiwukj.android.ufamily.mvp.http.utils.RxUtils;
import com.kaiwukj.android.ufamily.mvp.ui.page.service.ServiceContract;

import javax.inject.Inject;

import me.jessyan.rxerrorhandler.core.RxErrorHandler;

public class CommunityNoticePresenter extends BasePresenter<ServiceContract.Model, ServiceContract.CommunityNoticeView> {

    @Inject
    RxErrorHandler mErrorHandler;

    @Inject
    public CommunityNoticePresenter(ServiceContract.Model model, ServiceContract.CommunityNoticeView view) {
        super(model, view);
    }

    public void fetchNoticeList(int page, int pageSize) {
        mModel.fetchCommunityNotice(page, pageSize)
                .compose(RxUtils.schedulerHelper())
                .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
                .subscribe(new ApiCallBack<ListResp<CommunityNoticeResult>>(mErrorHandler, mRootView) {
                    @Override
                    public void onSuccess(@NonNull ListResp<CommunityNoticeResult> result) {
                        mRootView.onFetchResult(result.getList());
                    }
                });
    }

    public void getNoticeById(int id) {
        mModel.getCommunityNotice(id)
                .compose(RxUtils.schedulerHelper())
                .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
                .subscribe(new ApiCallBack<CommunityNoticeResult>(mErrorHandler, mRootView) {
                    @Override
                    public void onSuccess(@NonNull CommunityNoticeResult result) {
                        mRootView.onGetResult(result);
                    }
                });
    }

}
